


#ifndef PF_UNDOLISTITEM_H
#define PF_UNDOLISTITEM_H

#include <iostream>
#include <QList>
#include "lx_Export.h"

#include "pf_entity.h"
#include "pf_undoable.h"

/**
 * An Undo Cycle represents an action that was triggered and can 
 * be undone. It stores all the pointers to the Undoables affected by 
 * the action. Undoables are entities in a container that can be
 * created and deleted.
 *
 * Undo Cycles are stored within classes derrived from PF_Undo.
 *
 * @see PF_Undoable
 * @see PF_Undo
 *

 */
class LX_EXPORT PF_UndoCycle {
public:
    /**
     * @param type Type of undo item.
     */
    PF_UndoCycle(/*LX_Define::UndoType type*/) {
        //this->type = type;
    }

    /**
     * Adds an Undoable to this Undo Cycle. Every Cycle can contain one or
     * more Undoables.
     */
    void addUndoable(PF_Undoable* u) {
        undoables.append(u);
    }

    /**
     * Removes an undoable from the list.
     */
    void removeUndoable(PF_Undoable* u) {
        undoables.removeOne(u);
    }

    friend std::ostream& operator << (std::ostream& os,
                                      PF_UndoCycle& uc) {
        os << " Undo item: " << "\n";
        //os << "   Type: ";
        /*switch (i.type) {
        case LX_Define::UndoAdd:
            os << "LX_Define::UndoAdd";
            break;
        case LX_Define::UndoDel:
            os << "LX_Define::UndoDel";
            break;
    }*/
        os << "   Undoable ids: ";
        for (int i = 0; i < uc.undoables.size(); ++i) {
            PF_Undoable *u = uc.undoables.at(i);
            if (u->undoRtti()==LX_Define::UndoableEntity) {
                PF_Entity* e = (PF_Entity*)u;
                os << e->getId() << (u->isUndone() ? "*" : "") << " ";
            } else {
                os << "|";
            }

        }

        return os;
    }

    friend class PF_Undo;

private:
    //! Undo type:
    //LX_Define::UndoType type;
    //! List of entity id's that were affected by this action
    QList<PF_Undoable *> undoables;
};

#endif
